<template>
    <div ref="chartRef" class="lineChar"></div>
</template>

<script setup name="LineChart">
import * as echarts from 'echarts'
import { onMounted, ref } from 'vue'
import resize from './hooks/resize'
const chartRef = ref(null)

const { chartInstance } = resize()

onMounted(() => {
    initChart()
})

// 你可以在这里定义一个方法来初始化图表
function initChart() {
    // 基于准备好的dom，初始化echarts实例
    chartInstance.value = echarts.init(chartRef.value)
    // 指定图表.value的配置项和数据
    const option = {
        title: {
            text: 'ECharts 示例'
        },
        tooltip: {},
        legend: {
            data: ['销量']
        },
        xAxis: {
            data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
        },
        yAxis: {},
        series: [
            {
                name: '销量',
                type: 'bar',
                data: [5, 20, 36, 10, 10, 20]
            }
        ]
    }
    // 使用刚指定的配置项和数据显示图表。
    chartInstance.value.setOption(option)
}
</script>

<style lang="scss" scoped>
.lineChar {
    @include border;
    height: 350px;
    margin-top: 15px;
    margin-left: 15px;
    margin-right: 15px;
    border-radius: 10px;
}
</style>
